﻿<?php



function getUsersGameLists($userid){

require('_config-rating.php'); // get the db connection info

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
}


$sql = "SELECT * FROM gamelist WHERE userId =$userid ";

$rs_result = mysql_query($sql,$con); 
if($rs_result){
	while ($row = mysql_fetch_array($rs_result)) { 
		$selesctOption=$selesctOption.'<option value="'.$row["gameListId"].'">'.$row["gameListName"].'</option>';
	}
	echo $selesctOption;
}
mysql_close();
}

function getNextGame($currentGameId){
	
	require('_config-rating.php'); // get the db connection info

	
	if (!$con)
	  {
	  die('Could not connect: ' . mysql_error());
	}
	
	
	$sql = "SELECT * FROM games WHERE gameId > $currentGameId limit 0, 1 ";
	
	$rs_result = mysql_query($sql,$con); 
	if($rs_result){
		if($row = mysql_fetch_array($rs_result)){
			$nextGame = 'play.php?gameid='.$row["gameId"].'&game='.$row["gameName"].'';
		}
		echo $nextGame;
		/*while ($row = mysql_fetch_array($rs_result)) { 
			$selesctOption=$selesctOption.'<option value="'.$row["gameListId"].'">'.$row["gameListName"].'</option>';
		}
		echo $selesctOption;*/
	}
	
	mysql_close();
	
}

function getRandGame(){
require('_config-rating.php'); // get the db connection info
	
	if (!$con)
	  {
	  die('Could not connect: ' . mysql_error());
	}
	
	
	$sql = "SELECT max(gameId) FROM games";
	
	$rs_result = mysql_query($sql,$con); 
	if($rs_result){
		if($row = mysql_fetch_array($rs_result)){
			$maxId= $row["max(gameId)"];
			$randGId= rand(0,$maxId);
			$sql = "SELECT * FROM games where gameId = $randGId";
		
			$rs_result = mysql_query($sql,$con); 
		
			if($row = mysql_fetch_array($rs_result)){
				$randGame = 'play.php?gameid='.$row["gameId"].'&game='.$row["gameName"].'';
			}
		}
		echo $randGame;
	}
	/*while ($row = mysql_fetch_array($rs_result)) { 
		$selesctOption=$selesctOption.'<option value="'.$row["gameListId"].'">'.$row["gameListName"].'</option>';
	}
	echo $selesctOption;*/
	
	mysql_close();
	
}
?>